﻿using System;
using System.Diagnostics;
using System.Diagnostics.Contracts;

namespace Beaker.OpenCube.Render.Maths
{
	[DebuggerDisplay("{X}x{Y}")]
	public struct Size
		: IEquatable<Size>
	{
		public static readonly Size Zero = new Size( 0, 0 );

		private readonly int _width;
		private readonly int _height;

		public Size( int width, int height )
		{
			_width = width;
			_height = height;
		}

		#region Value

		/// <summary>
		/// Gets the width
		/// </summary>
		[Pure]
		public int Width
		{
			
			get { return _width; }
		}

		/// <summary>
		/// Gets the height
		/// </summary>
		[Pure]
		public int Height
		{
			
			get { return _height; }
		}

		#endregion

		#region Equality

		[Pure]
		public override bool Equals( object obj )
		{
			if( ReferenceEquals( null, obj ) ) return false;
			if( ReferenceEquals( this, obj ) ) return true;
			if( obj.GetType() != this.GetType() ) return false;
			return Equals( (Vector2)obj );
		}

		[Pure]
		public bool Equals( Size other )
		{
			if( ReferenceEquals( null, other ) ) return false;
			if( ReferenceEquals( this, other ) ) return true;
			return _width.Equals( other._width ) && _height.Equals( other._height );
		}

		[Pure]
		public static bool operator ==( Size left, Size right )
		{
			return Equals( left, right );
		}

		[Pure]
		public static bool operator !=( Size left, Size right )
		{
			return !Equals( left, right );
		}

		[Pure]
		public override int GetHashCode()
		{
			unchecked
			{
				int hashCode = _width.GetHashCode();
				hashCode = ( hashCode * 397 ) ^ _height.GetHashCode();
				return hashCode;
			}
		}

		#endregion
	}

}
